package com.xiaotu.util;

import com.xiaotu.config.WxConfig;
import org.springframework.web.client.RestTemplate;

/**
 * @author zhangxiao
 * @create 2021-08-19 10:13
 */
public class WxUtil {

    /**
     * 微信 session user
     */
    public static final String VX_SESSION_USER = "vx_session_user";

    private static RestTemplate restTemplate = new RestTemplate();

    private static String wxUrl = "?appid={appid}&secret={srcret}&js_code={code}&grant_type={grantType}";

    public static String getWxOpenIdSessionKey(String jsCode) {
        return restTemplate.getForObject(
                WxConfig.sessionHost + wxUrl, String.class,
                WxConfig.appId,
                WxConfig.secret,
                jsCode,
                WxConfig.grantType);
    }

}
